package com.cookie.libgdx.airforcecolonel;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Animator;

public class MainGame implements ApplicationListener {
	private Texture blueskyTexture;
	private TextureRegion blueskyTextureRegion;
	private SpriteBatch spriteBatch;
	private Texture backgroundTexture;
	
	private TextureRegion backgroundBackTexture;
	private TextureRegion backgroundUpTexture;
	private TextureRegion backgroundUp2Texture;
	private Animation backgroundUpTextureAnimation;
	private Animator animator;
	private TextureRegion[] animations = new TextureRegion[512];
	private float time;
	private float x;
	
	private int move;
	@Override
	public void create() {
		this.blueskyTexture = new Texture(Gdx.files.internal("data/Background.png"));
		this.backgroundTexture = new Texture(Gdx.files.internal("data/BackgroundSprit.png"));
		this.backgroundBackTexture = new TextureRegion(backgroundTexture, 0, 0, 800, 132);
		this.backgroundUpTexture = new TextureRegion(backgroundTexture, 0, 489, 800, 132);
		this.backgroundUp2Texture = new TextureRegion(backgroundTexture, 4, 489, 800, 132);
		for(int i=0;i<this.animations.length;i++){
			this.animations[i]= new TextureRegion(backgroundTexture, i, 489, 800-i, 132);
		}
		this.backgroundUpTextureAnimation = new Animation(0.1f,this.animations);
		this.blueskyTextureRegion = new TextureRegion(this.blueskyTexture, 0, 0, 800, 600);
		this.spriteBatch = new SpriteBatch();
	}

	@Override
	public void resume() {
		
	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		this.spriteBatch.begin();
		this.spriteBatch.draw(this.blueskyTextureRegion, 0, 0);
		this.spriteBatch.draw(this.backgroundBackTexture, 0, 0);
		//this.spriteBatch.draw(this.backgroundUpTexture, 0, 0);
		TextureRegion textrueRegion = this.backgroundUpTextureAnimation.getKeyFrame(time, true);
		//this.spriteBatch.draw(textrueRegion, 0, 0);
		//this.spriteBatch.draw(backgroundUpTexture, textrueRegion.getRegionWidth(), 0);
		
		this.spriteBatch.draw(backgroundUp2Texture, -x, 0);
		this.spriteBatch.draw(backgroundUp2Texture, 800-x-4f, 0);
		//this.spriteBatch.draw(backgroundUp2Texture, -(800-x-4f), 0);
		if(800-x-4f<=0){
			x=0;
		}
		x=x+10f;
		time+=0.2f;
		this.spriteBatch.end();
	}

	@Override
	public void resize(int width, int height) {
		
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void dispose() {
		
	}
	
}
